レプリケーション・スキームをスクリプトで作成すると、時間の節約および誤りの回避に有効です。この項では、Perlを使用してレプリケーション・スキームの作成を自動化する場合の推奨事項をいくつか示します。
例3.33に示す一般ワークロードの双方向スキームについて考えてみます。5つの表repl.accounts、repl.sales、repl.orders、repl.inventoryおよびrepl.customerへのELEMENT記述への入力を手動で行うと、時間がかかり、エラーも発生しやすくなります。
CREATE REPLICATION repl.bigscheme ELEMENT elem_accounts_1 TABLE repl.accounts MASTER westds ON "westcoast" SUBSCRIBER eastds ON "eastcoast" ELEMENT elem_accounts_2 TABLE repl.accounts MASTER eastds ON "eastcoast" SUBSCRIBER westds ON "westcoast" ELEMENT elem_sales_1 TABLE repl.sales MASTER westds ON "westcoast" SUBSCRIBER eastds ON "eastcoast" ELEMENT elem_sales_2 TABLE repl.sales MASTER eastds ON "eastcoast" SUBSCRIBER westds ON "westcoast" ELEMENT elem_orders_1 TABLE repl.orders MASTER westds ON "westcoast" SUBSCRIBER eastds ON "eastcoast" ELEMENT elem_orders_2 TABLE repl.orders MASTER eastds ON "eastcoast" SUBSCRIBER westds ON "westcoast" ELEMENT elem_inventory_1 TABLE repl.inventory MASTER westds ON "westcoast" SUBSCRIBER eastds ON "eastcoast" ELEMENT elem_inventory_2 TABLE repl.inventory MASTER eastds ON "eastcoast" SUBSCRIBER westds ON "westcoast" ELEMENT elem_customers_1 TABLE repl.customers MASTER westds ON "westcoast" SUBSCRIBER eastds ON "eastcoast" ELEMENT elem_customers_2 TABLE repl.customers MASTER eastds ON "eastcoast" SUBSCRIBER westds ON "westcoast";多くの場合、スクリプトを使用してレプリケーション・スキームの作成プロセスを自動化するとより効率的です。たとえば、例3.34に示すPerlスクリプトを使用して、例3.33に示したスキームを作成できます。
@tables = qw( repl.accounts repl.sales repl.orders repl.inventory repl.customers ); print "CREATE REPLICATION repl.bigscheme"; foreach $table (@tables) { $element = $table; $element =~ s/repl\./elem\_/; print "\n"; print " ELEMENT $element\_1 TABLE $table\n"; print " MASTER westds ON \"westcoast\"\n"; print " SUBSCRIBER eastds ON \"eastcoast\"\n"; print " ELEMENT $element\_2 TABLE $table\n"; print " MASTER eastds ON \"eastcoast\"\n"; print " SUBSCRIBER westds ON \"westcoast\""; } print ";\n";例3.34の@tables配列は、データ・ストアなどの他のソースから取得できます。たとえば、Perl文でttIsql文およびgrepを使用して、所有者名がreplのWestDSNデータ・ストア内のすべての表に対して@tables配列を生成できます。
@tables = `ttIsql -e "tables; quit" WestDSN | grep " repl\."`;例3.35に、WestDSNデータ・ストア内のすべてのrepl表に対してレプリケーション・スキームを作成する例3.34のスクリプトの変更バージョンを示します。(grep出力から余分な空白および改行を削除するには、置換を行う必要があります。)
@tables = `ttIsql -e "tables; quit" WestDSN | grep " repl\."`; print "CREATE REPLICATION repl.bigscheme"; foreach $table (@tables) { $table =~ s/^\s*//; # Remove extra spaces $table =~ s/\n//; # Remove line feeds $element = $table; $element =~ s/repl\./elem\_/; print "\n"; print " ELEMENT $element\_1 TABLE $table\n"; print " MASTER westds ON \"westcoast\"\n"; print " SUBSCRIBER eastds ON \"eastcoast\"\n"; print " ELEMENT $element\_2 TABLE $table\n"; print " MASTER eastds ON \"eastcoast\"\n"; print " SUBSCRIBER westds ON \"westcoast\""; } print ";\n";